package com.foodplus.www.view.fragments;


import android.os.Bundle;
import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.foodplus.www.adapter.special.SpecialAdapter;
import com.foodplus.www.foodplus.R;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * A simple {@link Fragment} subclass.
 */
public class SpecialFragment extends Fragment {

    @BindView(R.id.tab_special)
    TabLayout tabSpecial;
    @BindView(R.id.vp_special)
    ViewPager vpSpecial;
    private List<Fragment> fragments = new ArrayList<>();

    private String[] titles = {"视频", "榜单", "知识", "人文", "地图"};


    private SpecialAdapter adapter;


    public SpecialFragment() {
        // Required empty public constructor
    }

    public static SpecialFragment newInstance() {

        Bundle args = new Bundle();

        SpecialFragment fragment = new SpecialFragment();
        fragment.setArguments(args);
        return fragment;
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        View view = inflater.inflate(R.layout.fragment_special, container, false);
        ButterKnife.bind(this, view);
        adapter = new SpecialAdapter(getChildFragmentManager(), fragments, titles);
        initFragment();
        vpSpecial.setAdapter(adapter);
        tabSpecial.setupWithViewPager(vpSpecial);
        return view;
    }

    private void initFragment() {
        for (int i = 0; i < titles.length; i++) {
//            SpecialChildFragment specialChildFragment = SpecialChildFragment.newInstance(i);
//            fragments.add(specialChildFragment);
            fragments.add(SpecialChildFragment.newInstance(i));
        }
    }

}
